<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<script>
	    // 需求:写一个函数，功能：求某个指定的字符在字符串中出现的次数
		//参数两个：
		// 	1，被查找的字符串
		// 	2，指定的字符
		//方法一:
		/*function getCharCount(str,char){
			var count=0;
			var arr=str.split('');
			for(i=0;i<arr.length;i++){
                if(arr[i]===char){
                   count++;
                }
			}
			return count;
		}
		var num=getCharCount("abcabcaaaaabc","a");
		console.log(num);*/
		//方法二:
        /*function getCharCount(str,char){
			var count=0;
			var arr=str.split('');
			return str.split(char).length-1;
           }			
		   var num=getCharCount("abcabcaaaaaaabc","a");
		   console.log(num);*/
		// 需求:写一个函数，功能：求某个指定的字符串在字符串中出现的次数
		//参数两个：
		// 	1，被查找的字符串
		// 	2，指定的字符串
		//方法一:
		/*function getStringCount(bigStr,smallStr){
       	    var arr=bigStr.split('');
			return bigStr.split(smallStr).length-1;
		}
		var num=getStringCount("abcnuinabcniannabcjiojoiabcnonn","abc");
		console.log(num);*/
		//方法二:
		/*function getStringCount(bigStr,smallStr){
			var count=0;
			while(true){
              if(bigStr.indexOf(smallStr) != -1){
                 var index = bigStr.indexOf(smallStr)+smallStr.length;
                 bigStr = bigStr.substring(index);
                 count++;
              }else{
              	break;
              }
			}
			return count;
		}
		var num=getStringCount("abcnuinabcniannabcjiojoiabcnonn","abc");
		console.log(num);*/
		//方法三:
		var count=0;
		function getStringCount(bigStr,smallStr){
			
			if( bigStr.indexOf(smallStr) != -1 ){
				var index = bigStr.indexOf(smallStr)+smallStr.length;
				bigStr = bigStr.substring(index);
				count++;
				getStringCount(bigStr,smallStr);
			}
			return count;
		}
		var str = 'abcnuinabcniannabcjiojoiabcnonn';
		console.log(getStringCount(str,'abc'));
	</script>
</head>
<body>
	
</body>
</html>